package com.example.constellation.luckyfrag;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.constellation.R;
import com.example.constellation.bean.StarBean;
import com.example.constellation.utils.AssetsUtils;

import java.util.List;
import java.util.Map;

import de.hdodenhof.circleimageview.CircleImageView;

public class LuckBaseAdapter extends BaseAdapter {
    private final Map<String, Bitmap> contentlogoImgMap;
    Context context;
    List<StarBean.StarinfoBean> mDatas;

    public LuckBaseAdapter(Context context, List<StarBean.StarinfoBean> mDatas) {
        contentlogoImgMap= AssetsUtils.getContentlogoImgMap();
        this.context = context;
        this.mDatas = mDatas;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int i) {
        return mDatas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder holder=null;
        if(view==null)
        {
            view= LayoutInflater.from(context).inflate(R.layout.item_luck_gv,null);
            holder=new ViewHolder(view);
            view.setTag(holder);
        }else
        {
            holder=(ViewHolder) view.getTag();
        }
        //获取指定的位置
        StarBean.StarinfoBean bean=mDatas.get(i);
        holder.starTv.setText(bean.getName());
//通过名称 获取存储在内存当中的图片 然后进行设置
        Bitmap bitmap = contentlogoImgMap.get(bean.getLogoname());
        holder.starIv.setImageBitmap(bitmap);


        return view;
    }


    class ViewHolder{
        CircleImageView starIv;
        TextView starTv;
        public ViewHolder(View view){
            starIv=view.findViewById(R.id.item_luck_iv);
            starTv=view.findViewById(R.id.item_luck_tv);

        }

    }

}
